package com.rzx.dim4status.utils;

import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * @Author: kabudac
 * @Date: 2023/8/16
 * @Description: 封装结果集
 */
@Data
public class Result {
    /**
     * 响应状态码
     */
    private Integer code;
    /**
     * 响应消息
     */
    private String msg;
    /**
     * 响应数据
     */
    private Object data;

    private static final String MSG_OK = "ok";
    private static final String MSG_FAIL = "fail";

    private Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result ok(Object data) {
        return new Result(HttpStatus.OK.value(), MSG_OK, data);
    }

    public static Result ok(){
        return new Result(HttpStatus.OK.value(), MSG_OK, null);
    }
    public static Result ok(String msg,Object data){
        return new Result(HttpStatus.OK.value(), msg, data);
    }

    public static Result ok(String msg) {
        return new Result(HttpStatus.OK.value(), msg, null);
    }

    public static Result fail(String msg) {
        return new Result(HttpStatus.BAD_REQUEST.value(), msg, null);
    }

    public static Result fail() {
        return new Result(HttpStatus.BAD_REQUEST.value(), MSG_FAIL, null);
    }

    public static Result fail(Integer code, String msg) {
        return new Result(code, msg, null);
    }
}
